package com.grpc.service;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.springframework.stereotype.Service;
import talkischeap.GreeterGrpc;
import talkischeap.HelloReply;
import talkischeap.HelloRequest;

/**
 * create by yongli on 2022-04-14 15:36
 */
@Service
public class RemoteService {

    public HelloReply sayHello(HelloRequest request) {
        // plain，否则报tls
        ManagedChannelBuilder channelBuilder = ManagedChannelBuilder.forAddress("127.0.0.1", 8081).usePlaintext();
        ManagedChannel channel = channelBuilder.build();
        HelloRequest helloRequest = HelloRequest.newBuilder().setName("liyong").build();
        return GreeterGrpc.newBlockingStub(channel).sayHello(helloRequest);
    }
}
